package com.gitee.denger.mybatis.example.ext.analytical;

import com.gitee.denger.mybatis.example.ext.util.SimpleReflectionUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class ExampleCriteriaValueImpl4Object implements IExampleCriteriaValue {

    @Override
    public void setForTk(Annotation annotation, Object criteria, String fieldName, Object fieldValue) {
        String methodName = lowerCaseForFirst(annotation.annotationType().getSimpleName());
        Method method = SimpleReflectionUtils.findMethod(criteria.getClass(), methodName, String.class, Object.class);
        //criteria赋值
        SimpleReflectionUtils.invokeMethod(method, criteria, fieldName, fieldValue);
    }

    @Override
    public void set(Annotation annotation, Object criteria, String fieldName, Object fieldValue) {
        Method method = SimpleReflectionUtils.findMethod(criteria.getClass(), getMethodName(annotation, fieldName), fieldValue.getClass());
        //criteria赋值
        SimpleReflectionUtils.invokeMethod(method, criteria, fieldValue);
    }
}